package com.ylq.todolsitserver.service.impl;

import com.ylq.todolsitserver.entity.Category;
import com.ylq.todolsitserver.mapper.CategoryMapper;
import com.ylq.todolsitserver.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {

    private final CategoryMapper categoryMapper;

    @Autowired
    public CategoryServiceImpl(CategoryMapper categoryMapper) {
        this.categoryMapper = categoryMapper;
    }

    @Override
    public Category createCategory(Category category) {
        categoryMapper.insert(category);
        return categoryMapper.findById(category.getId());
    }

    @Override
    public List<Category> getAllCategories() {
        return categoryMapper.findAll();
    }

    @Override
    public Category updateCategory(Integer id, Category category) {
        category.setId(id);
        categoryMapper.update(category);
        return categoryMapper.findById(id);
    }

    @Override
    public void deleteCategory(Integer id) {
        categoryMapper.delete(id);
    }
}